package com.rmb.service.impl;

import com.rmb.mapper.RecordMapper;
import com.rmb.mart.entity.workbench.RecordTwo;
import com.rmb.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName RecordServiceImpl
 * @Description TODO
 * @Author lvshook
 * @Date 2021/1/22 8:35
 * @Version 1.0
 **/
@Service
public class RecordServiceImpl implements RecordService {

    @Autowired(required = false)
    private RecordMapper recordMapper;

    /**
     * 循环次数
     */
    public static final float NUM = 30;
    /**
     * hashmap 初始扩容
     */
    public static final int INIT = 2000;


    /**
     * 查询
     * @param recordTwo
     * @return
     */
    @Override
    public Map getRecord(RecordTwo recordTwo) {

        //给usetime赋当前年月
        if (recordTwo.getUseTime() == null){
            Calendar calendar = Calendar.getInstance();
            int i = calendar.get(Calendar.YEAR);
            int i1 = calendar.get(Calendar.MONTH);
            String date = i+"-"+i1+1+"";
            recordTwo.setUseTime(date);
        }
        //创建list对象
        List list = new ArrayList<>();

        //循环拼接字符串
        String data = "";
        for (int i = 1; i < NUM; i++) {
            data = recordTwo.getUseTime()+"-"+i;
            list.add(data);
        }
        //创建map集合
        Map m = new HashMap<>(INIT);

        for (int i = 0; i < list.size(); i++) {
            int num = recordMapper.findNum(recordTwo.getId(), recordTwo.getMartApiEssentialId(), list.get(i));
            m.put(list.get(i),num);
        }

        Set set = m.entrySet();
        System.out.println("-------------"+set);


        return m;
    }
}
